home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / TGE129C.ZIP / SOURCE / 320X240.ASM < prev    next >
Assembly Source File  |  1993-08-20  |  31KB  |  1,582 lines

  1. ; 320x240x256 (requires register-compatible VGA+)
  2. ; Loadable driver for The Graphics Engine
  3. ; Copyright (c) 1993 by Matthew Hildebrand
  4. ; Turbo Assembler syntax
  5.  
  6. IDEAL
  7. P486N            ; 386 code, but we want 486 alignment
  8. MODEL LARGE
  9.  
  10.  
  11. SCREEN_WIDE    =    320
  12. SCREEN_DEEP    =    240
  13. NUM_COLOURS    =    256
  14.  
  15.  
  16.         CODESEG
  17.         ORG    0
  18.  
  19. ;*** Signature
  20.             db    'TGE3'
  21. ;*** Non-I/O functions
  22. _initGraphics        dw    initGraphics        ; initGraphics
  23.             dw    ?
  24. _deInitGraphics        dw    0            ; deInitGraphics
  25.             dw    ?
  26. _setPaletteReg        dw    setPaletteReg        ; setPaletteReg
  27.             dw    ?
  28. _getPaletteReg        dw    getPaletteReg        ; getPaletteReg
  29.             dw    ?
  30. _setBlockPalette    dw    setBlockPalette        ; setBlockPalette
  31.             dw    ?
  32. _getBlockPalette    dw    getBlockPalette        ; getBlockPalette
  33.             dw    ?
  34. _colourCloseTo        dw    0            ; colourCloseTo
  35.             dw    ?
  36. _colourCloseToX        dw    0            ; colourCloseToX
  37.             dw    ?
  38. _imageSize        dw    0            ; imageSize
  39.             dw    ?
  40. _imageSizeDim        dw    0            ; imageSizeDim
  41.             dw    ?
  42. _setPage        dw    0            ; setPage (not implemented yet)
  43.             dw    ?
  44.  
  45. ;*** Currently active I/O functions (filled in by loadGraphDriver())
  46.             dd    20    DUP(?)
  47.  
  48. ;*** Input functions
  49. _getImage_scr        dw    0            ; getImage
  50.             dw    ?
  51. _getImage_mem        dw    0
  52.             dw    ?
  53. _getLine_scr        dw      getLine_scr              ; getLine
  54.             dw    ?
  55. _getLine_mem        dw    getLine_mem
  56.             dw    ?
  57. _getPixel_scr        dw    getPixel_scr        ; getPixel
  58.             dw    ?
  59. _getPixel_mem        dw    getPixel_mem
  60.             dw    ?
  61.  
  62. ;*** Output functions
  63. _putImage_scr_copy    dw    0            ; putImage
  64.             dw    ?
  65. _putImage_scr_and    dw    0
  66.             dw    ?
  67. _putImage_scr_not    dw    0
  68.             dw    ?
  69. _putImage_scr_or    dw    0
  70.             dw    ?
  71. _putImage_scr_xor    dw    0
  72.             dw    ?
  73. _putImage_mem_copy    dw    0
  74.             dw    ?
  75. _putImage_mem_and    dw    0
  76.             dw    ?
  77. _putImage_mem_not    dw    0
  78.             dw    ?
  79. _putImage_mem_or    dw    0
  80.             dw    ?
  81. _putImage_mem_xor    dw    0
  82.             dw    ?
  83. _putImageInv_scr_copy    dw    0            ; putImageInv
  84.             dw    ?
  85. _putImageInv_scr_and    dw    0
  86.             dw    ?
  87. _putImageInv_scr_not    dw      0
  88.             dw    ?
  89. _putImageInv_scr_or    dw      0
  90.             dw    ?
  91. _putImageInv_scr_xor    dw    0
  92.             dw    ?
  93. _putImageInv_mem_copy    dw    0
  94.             dw    ?
  95. _putImageInv_mem_and    dw    0
  96.             dw    ?
  97. _putImageInv_mem_not    dw    0
  98.             dw    ?
  99. _putImageInv_mem_or    dw    0
  100.             dw    ?
  101. _putImageInv_mem_xor    dw    0
  102.             dw    ?
  103. _putLine_scr_copy          dw    putLine_scr_copy    ; putLine
  104.             dw    ?
  105. _putLine_scr_and          dw      0
  106.             dw    ?
  107. _putLine_scr_not          dw      0
  108.             dw    ?
  109. _putLine_scr_or          dw      0
  110.             dw    ?
  111. _putLine_scr_xor          dw    0
  112.             dw    ?
  113. _putLine_mem_copy    dw      putLine_mem_copy
  114.             dw    ?
  115. _putLine_mem_and    dw      0
  116.             dw    ?
  117. _putLine_mem_not    dw      0
  118.             dw    ?
  119. _putLine_mem_or        dw      0
  120.             dw    ?
  121. _putLine_mem_xor    dw    0
  122.             dw    ?
  123. _putLineInv_scr_copy       dw    0            ; putLineInv
  124.             dw    ?
  125. _putLineInv_scr_and       dw    0
  126.             dw    ?
  127. _putLineInv_scr_not       dw    0
  128.             dw    ?
  129. _putLineInv_scr_or       dw    0
  130.             dw    ?
  131. _putLineInv_scr_xor       dw    0
  132.             dw    ?
  133. _putLineInv_mem_copy    dw    0
  134.             dw    ?
  135. _putLineInv_mem_and    dw    0
  136.             dw    ?
  137. _putLineInv_mem_not    dw    0
  138.             dw    ?
  139. _putLineInv_mem_or    dw    0
  140.             dw    ?
  141. _putLineInv_mem_xor    dw    0
  142.             dw    ?
  143. _putPixel_scr_copy    dw    putPixel_scr_copy    ; putPixel
  144.             dw    ?
  145. _putPixel_scr_and    dw      0
  146.             dw    ?
  147. _putPixel_scr_not    dw      0
  148.             dw    ?
  149. _putPixel_scr_or    dw      0
  150.             dw    ?
  151. _putPixel_scr_xor    dw    0
  152.             dw    ?
  153. _putPixel_mem_copy    dw    putPixel_mem_copy
  154.             dw    ?
  155. _putPixel_mem_and    dw      putPixel_mem_and
  156.             dw    ?
  157. _putPixel_mem_not    dw      putPixel_mem_not
  158.             dw    ?
  159. _putPixel_mem_or    dw      putPixel_mem_or
  160.             dw    ?
  161. _putPixel_mem_xor    dw    putPixel_mem_xor
  162.             dw    ?
  163. _line_scr_copy        dw    0            ; line
  164.             dw    ?
  165. _line_scr_and        dw      0
  166.             dw    ?
  167. _line_scr_not        dw      0
  168.             dw    ?
  169. _line_scr_or        dw      0
  170.             dw    ?
  171. _line_scr_xor        dw    0
  172.             dw    ?
  173. _line_mem_copy        dw    0
  174.             dw    ?
  175. _line_mem_and        dw    0
  176.             dw    ?
  177. _line_mem_not        dw    0
  178.             dw    ?
  179. _line_mem_or        dw    0
  180.             dw    ?
  181. _line_mem_xor        dw    0
  182.             dw    ?
  183. _horizLine_scr_copy    dw    horizLine_scr_copy      ; horizLine
  184.             dw    ?
  185. _horizLine_scr_and    dw      0
  186.             dw    ?
  187. _horizLine_scr_not    dw      0
  188.             dw    ?
  189. _horizLine_scr_or    dw      0
  190.             dw    ?
  191. _horizLine_scr_xor    dw    0
  192.             dw    ?
  193. _horizLine_mem_copy    dw    horizLine_mem_copy
  194.             dw    ?
  195. _horizLine_mem_and    dw      0
  196.             dw    ?
  197. _horizLine_mem_not    dw      0
  198.             dw    ?
  199. _horizLine_mem_or    dw      0
  200.             dw    ?
  201. _horizLine_mem_xor    dw    0
  202.             dw    ?
  203. _vertLine_scr_copy    dw    0             ; vertLine
  204.             dw    ?
  205. _vertLine_scr_and    dw    0
  206.             dw    ?
  207. _vertLine_scr_not    dw    0
  208.             dw    ?
  209. _vertLine_scr_or    dw    0
  210.             dw    ?
  211. _vertLine_scr_xor    dw    0
  212.             dw    ?
  213. _vertLine_mem_copy    dw    0
  214.             dw    ?
  215. _vertLine_mem_and    dw    0
  216.             dw    ?
  217. _vertLine_mem_not    dw    0
  218.             dw    ?
  219. _vertLine_mem_or    dw    0
  220.             dw    ?
  221. _vertLine_mem_xor    dw    0
  222.             dw    ?
  223. _drawRect_scr_copy    dw    0            ; drawRect
  224.             dw    ?
  225. _drawRect_scr_and    dw    0
  226.             dw    ?
  227. _drawRect_scr_not    dw    0
  228.             dw    ?
  229. _drawRect_scr_or    dw    0
  230.             dw    ?
  231. _drawRect_scr_xor    dw    0
  232.             dw    ?
  233. _drawRect_mem_copy    dw    0
  234.             dw    ?
  235. _drawRect_mem_and    dw    0
  236.             dw    ?
  237. _drawRect_mem_not    dw    0
  238.             dw    ?
  239. _drawRect_mem_or    dw    0
  240.             dw    ?
  241. _drawRect_mem_xor    dw    0
  242.             dw    ?
  243. _filledRect_scr_copy    dw    0            ; filledRect
  244.             dw    ?
  245. _filledRect_scr_and    dw      0
  246.             dw    ?
  247. _filledRect_scr_not    dw      0
  248.             dw    ?
  249. _filledRect_scr_or    dw      0
  250.             dw    ?
  251. _filledRect_scr_xor    dw    0
  252.             dw    ?
  253. _filledRect_mem_copy    dw    0
  254.             dw    ?
  255. _filledRect_mem_and    dw    0
  256.             dw    ?
  257. _filledRect_mem_not    dw    0
  258.             dw    ?
  259. _filledRect_mem_or    dw    0
  260.             dw    ?
  261. _filledRect_mem_xor    dw    0
  262.             dw    ?
  263. _clearGraphics_scr_copy    dw    clearGraphics_scr_copy    ; clearGraphics
  264.             dw    ?
  265. _clearGraphics_scr_and    dw      0
  266.             dw    ?
  267. _clearGraphics_scr_not    dw      0
  268.                   dw    ?
  269. _clearGraphics_scr_or    dw      0
  270.             dw    ?
  271. _clearGraphics_scr_xor    dw    0
  272.             dw    ?
  273. _clearGraphics_mem_copy    dw    0
  274.             dw    ?
  275. _clearGraphics_mem_and    dw    0
  276.             dw    ?
  277. _clearGraphics_mem_not    dw    0
  278.             dw    ?
  279. _clearGraphics_mem_or    dw    0
  280.             dw    ?
  281. _clearGraphics_mem_xor    dw    0
  282.             dw    ?
  283. _ellipse_scr_copy    dw    0            ; ellipse
  284.             dw    ?
  285. _ellipse_scr_and    dw    0
  286.             dw    ?
  287. _ellipse_scr_not    dw    0
  288.             dw    ?
  289. _ellipse_scr_or        dw    0
  290.             dw    ?
  291. _ellipse_scr_xor    dw    0
  292.             dw    ?
  293. _ellipse_mem_copy    dw    0
  294.             dw    ?
  295. _ellipse_mem_and    dw    0
  296.             dw    ?
  297. _ellipse_mem_not    dw    0
  298.             dw    ?
  299. _ellipse_mem_or        dw    0
  300.             dw    ?
  301. _ellipse_mem_xor    dw    0
  302.             dw    ?
  303. _filledEllipse_scr_copy    dw    0            ; filledEllipse
  304.             dw    ?
  305. _filledEllipse_scr_and    dw    0
  306.             dw    ?
  307. _filledEllipse_scr_not    dw    0
  308.             dw    ?
  309. _filledEllipse_scr_or    dw    0
  310.             dw    ?
  311. _filledEllipse_scr_xor    dw    0
  312.             dw    ?
  313. _filledEllipse_mem_copy    dw    0
  314.             dw    ?
  315. _filledEllipse_mem_and    dw    0
  316.             dw    ?
  317. _filledEllipse_mem_not    dw    0
  318.             dw    ?
  319. _filledEllipse_mem_or    dw    0
  320.             dw    ?
  321. _filledEllipse_mem_xor    dw    0
  322.             dw    ?
  323. _circle_scr_copy    dw    0            ; circle
  324.             dw    ?
  325. _circle_scr_and        dw    0
  326.             dw    ?
  327. _circle_scr_not        dw    0
  328.             dw    ?
  329. _circle_scr_or        dw    0
  330.             dw    ?
  331. _circle_scr_xor        dw    0
  332.             dw    ?
  333. _circle_mem_copy    dw    0
  334.             dw    ?
  335. _circle_mem_and        dw    0
  336.             dw    ?
  337. _circle_mem_not        dw    0
  338.             dw    ?
  339. _circle_mem_or        dw    0
  340.             dw    ?
  341. _circle_mem_xor        dw    0
  342.             dw    ?
  343. _filledCircle_scr_copy    dw    0            ; filledCircle
  344.             dw    ?
  345. _filledCircle_scr_and    dw    0
  346.             dw    ?
  347. _filledCircle_scr_not    dw    0
  348.             dw    ?
  349. _filledCircle_scr_or    dw    0
  350.             dw    ?
  351. _filledCircle_scr_xor    dw    0
  352.             dw    ?
  353. _filledCircle_mem_copy    dw    0
  354.             dw    ?
  355. _filledCircle_mem_and    dw    0
  356.             dw    ?
  357. _filledCircle_mem_not    dw    0
  358.             dw    ?
  359. _filledCircle_mem_or    dw    0
  360.             dw    ?
  361. _filledCircle_mem_xor    dw    0
  362.             dw    ?
  363. _fillRegion_scr_copy    dw    0            ; fillRegion
  364.             dw    ?
  365. _fillRegion_scr_and    dw    0
  366.             dw    ?
  367. _fillRegion_scr_not    dw    0
  368.             dw    ?
  369. _fillRegion_scr_or    dw    0
  370.             dw    ?
  371. _fillRegion_scr_xor    dw    0
  372.             dw    ?
  373. _fillRegion_mem_copy    dw    0
  374.             dw    ?
  375. _fillRegion_mem_and    dw    0
  376.             dw    ?
  377. _fillRegion_mem_not    dw    0
  378.             dw    ?
  379. _fillRegion_mem_or    dw    0
  380.             dw    ?
  381. _fillRegion_mem_xor    dw    0
  382.             dw    ?
  383. _fillLine_scr_copy    dw    horizLine_scr_copy    ; fillLine
  384.             dw    ?
  385. _fillLine_scr_and    dw      0
  386.             dw    ?
  387. _fillLine_scr_not    dw      0
  388.             dw    ?
  389. _fillLine_scr_or    dw      0
  390.             dw    ?
  391. _fillLine_scr_xor    dw    0
  392.             dw    ?
  393. _fillLine_mem_copy    dw    horizLine_mem_copy
  394.             dw    ?
  395. _fillLine_mem_and    dw      0
  396.             dw    ?
  397. _fillLine_mem_not    dw      0
  398.             dw    ?
  399. _fillLine_mem_or    dw      0
  400.             dw    ?
  401. _fillLine_mem_xor    dw    0
  402.             dw    ?
  403. ;*** Mode information
  404. scrnMaxX        dw    319    ; physical dimensions
  405. scrnMaxY        dw    239
  406. maxColour        dw    255    ; maximum colour number
  407. xRatio                   dw    4    ; aspect ratio 4:3 (320:240 in
  408. yRatio            dw    3    ;   lowest terms)
  409. bitsPerPixel        dw    8    ; 8 bits per pixel
  410. inMaxX            dw    319    ; current input screen dimensions
  411. inMaxY            dw    239
  412. outMaxX            dw    319    ; current output screen dimensions
  413. outMaxY            dw    239
  414. inScreenWide        dw    ?    ; needed only for virtual screens
  415. outScreenWide        dw    ?
  416. ;*** Viewport information
  417. inViewportULX        dw    0
  418. inViewportULY        dw    0
  419. inViewportLRX        dw    319
  420. inViewportLRY        dw    239
  421. outViewportULX        dw    0
  422. outViewportULY        dw    0
  423. outViewportLRX        dw    319
  424. outViewportLRY        dw    239
  425. ;*** Paging information
  426. pagingSupported        dw    ?    ; not implemented yet
  427. curPage            dw    ?    ; not implemented yet
  428. maxPage            dw    ?    ; not implemented yet
  429. ;*** Force (image width MOD imageWideAdjust) = 0.
  430. imageWideAdjust        dw    ?    ; not implemented yet
  431. ;*** Current and screen addresses
  432.     LABEL    inAddr    DWORD        ; current input address
  433. inOff    dw    0
  434. inSeg    dw    0A000h
  435.     LABEL    outAddr    DWORD        ; current output address
  436. outOff    dw    0
  437. outSeg    dw    0A000h
  438.     LABEL    scrAddr    DWORD        ; screen address
  439. scrOff    dw    0
  440. scrSeg    dw    0A000h
  441. ;*** Copyright string
  442.     db    'The Graphics Engine -- Copyright (c) 1993 by Matthew Hildebrand'
  443.  
  444.  
  445. inited        db    0
  446. colourPalette    db    768    DUP(?)
  447. lineOffs    dw    240    DUP(?)
  448.  
  449. ; Plane masks for horizLine
  450. leftEdgeMask    db    1111b, 1110b, 1100b, 1000b
  451. rightEdgeMask    db    0001b, 0011b, 0111b, 1111b
  452.  
  453.  
  454. SC_INDEX    EQU    3C4h    ; Sequence Controller Index
  455. GC_INDEX    EQU    3CEh    ; Graphics Controller Index register
  456. CRTC_INDEX    EQU    3D4h    ; CRT Controller Index
  457. MISC_OUTPUT    EQU    3C2h    ; Miscellaneous Output register
  458. MAP_MASK    EQU     02h     ; index in SC of Map Mask register
  459. READ_MAP    EQU    4    ; Read Map register index in GC
  460. MEMORY_MODE    EQU    4    ; Memory mode register in SC
  461. GRAPHICS_MODE    EQU    5    ; Graphics Mode register index in GC
  462. MISCELLANEOUS    EQU    6    ; Miscellaneous register index in GC
  463. MAX_SCAN_LINE    EQU    9          ; Maximum Scan Line reg index in CRTC
  464. START_ADDR_HIGH    EQU    0Ch    ; Start Address High reg index in CRTC
  465. UNDERLINE    EQU    14h    ; Underline Location reg index in CRTC
  466. MODE_CONTROL    EQU    17h    ; Mode Control register index in CRTC
  467. INPUT_STATUS_1  EQU     03DAh   ; Input Status 1 register
  468. START_ADDR_HIGH EQU    0Ch     ; start address high byte
  469. START_ADDR_LOW  EQU    0Dh     ; start address low byte
  470. WORD_OUTS_OK    EQU    1    ; Set to 0 for VGAs that can't handle
  471.                 ; word OUTs to indexed VGA registers
  472.  
  473.  
  474. MACRO    OUT_WORD
  475. if WORD_OUTS_OK
  476.   out    dx,ax
  477. else
  478.   out    dx,al
  479.   inc    dx
  480.   xchg    ah,al
  481.   out    dx,al
  482.   dec    dx
  483.   xchg    ah,al
  484. endif
  485. ENDM
  486.  
  487.  
  488. ;*****
  489. ;***** initGraphics
  490. ;*****
  491.  
  492. PROC    C    initGraphics
  493.   push    si di
  494.  
  495.   mov   ax,0013h            ; set mode 13h
  496.   int   10h
  497.  
  498.   mov   dx,SC_INDEX
  499.   mov   ax,0604h
  500.   out   dx,ax               ; disable chain4 mode
  501.   mov   ax,0100h
  502.   out   dx,ax               ; synchronous reset while setting
  503.                       ; Misc Output for safety, even
  504.                     ; though clock unchanged
  505.  
  506.   mov   dx,MISC_OUTPUT
  507.   mov   al,0E3h
  508.   out   dx,al                ; select 25 MHz dot clock & 60 Hz
  509.                       ; scanning rate
  510.  
  511.   mov   dx,SC_INDEX
  512.   mov   ax,0300h
  513.   out   dx,ax                ; undo reset (restart sequencer)
  514.  
  515.   mov   dx,CRTC_INDEX             ; reprogram the CRT Controller
  516.   mov   al,11h              ; VSync End reg contains register
  517.   out   dx,al               ; write protect bit
  518.   inc   dx                  ; CRT Controller Data register
  519.   in    al,dx               ; get current VSync End register setting
  520.   and   al,7Fh              ; remove write protect on various
  521.   out   dx,al               ; CRTC registers
  522.   dec   dx                  ; CRT Controller Index
  523.  
  524.   mov    ax,00D06h            ; set CRT parameters
  525.   out    dx,ax
  526.   mov    ax,03E07h
  527.   out    dx,ax
  528.   mov    ax,04109h
  529.   out    dx,ax
  530.   mov    ax,0EA10h
  531.   out    dx,ax
  532.   mov    ax,0AC11h
  533.   out    dx,ax
  534.   mov    ax,0DF12h
  535.   out    dx,ax
  536.   mov    ax,00014h
  537.   out    dx,ax
  538.   mov    ax,0E715h
  539.   out    dx,ax
  540.   mov    ax,00616h
  541.   out    dx,ax
  542.   mov    ax,0E317h
  543.   out    dx,ax
  544.  
  545.   mov   dx,SC_INDEX
  546.   mov   ax,0F02h
  547.   out   dx,ax               ; enable writes to all four planes
  548.   mov   ax,0A000h              ; now clear all display memory, 8
  549.   mov   es,ax                     ; pixels at a time
  550.   xor   di,di               ; point ES:DI to display memory
  551.   xor   ax,ax               ; clear to zero-value pixels
  552.   mov   cx,8000h             ; # of words in display memory
  553.   rep   stosw               ; clear all of display memory
  554.  
  555.   cmp    [inited],0            ; restore palette if necessary
  556.   je    @@notInited
  557.   pop    di si
  558.   mov    ax,1
  559.   retf
  560.  
  561.     @@notInited:
  562.   mov    [inited],1
  563.   mov    si,OFFSET lineOffs
  564.   mov    cx,SCREEN_DEEP
  565.   xor    bx,bx
  566.  
  567.     @@LLoop:
  568.   mov    ax,SCREEN_WIDE/4
  569.   mul    bx
  570.   mov    [cs:si],ax
  571.   add    si,2
  572.   inc    bx
  573.   loop    @@LLoop
  574.  
  575.   pop   di si
  576.   mov    ax,1
  577.   retf
  578. ENDP
  579.  
  580.  
  581. ;*****
  582. ;***** putLine
  583. ;*****
  584.  
  585. PROC    C    putLine_scr_copy
  586.     ARG    lineNum:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  587.         LOCAL    x2:WORD
  588.   push    ds si di
  589.  
  590.   mov    bx,[lineNum]            ; start address in ES:DI
  591.   shl    bx,1
  592.   mov    di,[lineOffs+bx]
  593.   mov    dx,[xOff]
  594.   shr    dx,2
  595.   add    di,dx
  596.   mov    ax,0A000h
  597.   mov    es,ax
  598.   lds    si,[buf]            ; source in DS:SI
  599.   cld
  600.  
  601.   mov    bx,[xOff]
  602.   add    bx,[lineLen]            ; calculate x2
  603.   dec    bx
  604.   mov    [x2],bx
  605.  
  606.   mov    cx,[lineLen]            ; line is short
  607.   cmp    cx,4
  608. JUMPS
  609.   jle    @@ShortLine
  610. NOJUMPS
  611.  
  612.   mov    cx,[xOff]            ; calculate starting plane
  613.   mov    bx,cx
  614.   mov    ax,0102h
  615.   and    cl,3
  616.   shl    ah,cl
  617.   mov    dx,SC_INDEX
  618.   OUT_WORD
  619.   push    si
  620.   mov    bx,[x2]
  621.   mov    cx,[xOff]
  622.       @@Loop1:
  623.   cmp    cx,bx
  624.   jg    @@Loop1Done
  625.   lodsb
  626.   stosb
  627.   add    cx,4
  628.   add    si,3
  629.   jmp    short    @@Loop1
  630.  
  631.     @@Loop1Done:
  632.   pop    si
  633.   inc    si
  634.   push    si
  635.   mov    bx,[xOff]
  636.   inc    bx
  637.   mov    cx,bx
  638.   mov    ax,0102h
  639.   and    cl,3
  640.   shl    ah,cl
  641.   mov    dx,SC_INDEX
  642.   OUT_WORD
  643.   mov    cx,bx
  644.   mov    bx,[lineNum]            ; start address in ES:DI
  645.   shl    bx,1
  646.   mov    di,[lineOffs+bx]
  647.   shr    cx,2
  648.   add    di,cx
  649.   mov    bx,[x2]
  650.   mov    cx,[xOff]
  651.   inc    cx
  652.       @@Loop2:
  653.   cmp    cx,bx
  654.   jg    @@Loop2Done
  655.   lodsb
  656.   stosb
  657.   add    cx,4
  658.   add    si,3
  659.   jmp    short    @@Loop2
  660.  
  661.       @@Loop2Done:
  662.   pop    si
  663.   inc    si
  664.   push    si
  665.   mov    bx,[xOff]
  666.   add    bx,2
  667.   mov    cx,bx
  668.   mov    ax,0102h
  669.   and    cl,3
  670.   shl    ah,cl
  671.   mov    dx,SC_INDEX
  672.   OUT_WORD
  673.   mov    cx,bx
  674.   mov    bx,[lineNum]
  675.   shl    bx,1
  676.   mov    di,[lineOffs+bx]
  677.   shr    cx,2
  678.   add    di,cx
  679.   mov    bx,[x2]
  680.   mov    cx,[xOff]
  681.   add    cx,2
  682.       @@Loop3:
  683.   cmp    cx,bx
  684.   jg    @@Loop3Done
  685.   lodsb
  686.   stosb
  687.   add    cx,4
  688.   add    si,3
  689.   jmp    short    @@Loop3
  690.  
  691.     @@Loop3Done:
  692.   pop    si
  693.   inc    si
  694.   mov    bx,[xOff]
  695.   add    bx,3
  696.   mov    cx,bx
  697.   mov    ax,0102h
  698.   and    cl,3
  699.   shl    ah,cl
  700.   mov    dx,SC_INDEX
  701.   OUT_WORD
  702.   mov    cx,bx
  703.   mov    bx,[lineNum]
  704.   shl    bx,1
  705.   mov    di,[lineOffs+bx]
  706.   shr    cx,2
  707.   add    di,cx
  708.   mov    bx,[x2]
  709.   mov    cx,[xOff]
  710.   add    cx,3
  711.     @@Loop4:
  712.   cmp    cx,bx
  713.   jg    @@Exit
  714.   lodsb
  715.   stosb
  716.   add    cx,4
  717.   add    si,3
  718.   jmp    short    @@Loop4
  719.  
  720.       @@ShortLine:
  721.   mov    cx,[xOff]
  722.   mov    bx,cx
  723.   and    cl,3
  724.   mov    ax,0102h
  725.   shl    ah,cl
  726.   mov    dx,SC_INDEX
  727.   OUT_WORD
  728.   mov    cx,bx
  729.   shr    bx,2
  730.   mov    di,bx
  731.   mov    bx,[lineNum]
  732.   shl    bx,1
  733.   add    di,[lineOffs+bx]
  734.   movsb
  735.   cmp    cx,[x2]
  736.   jge    @@Exit
  737.   inc    [xOff]
  738.   jmp    short    @@ShortLine
  739.  
  740.       @@Exit:
  741.   pop   di si ds
  742.   leave
  743.   retf
  744. ENDP
  745.  
  746. PROC    C    putLine_mem_copy
  747.     ARG    y:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  748.   push    ds si di            ; save these registers
  749.  
  750.   xor    eax,eax                ; clear EAX
  751.   xor    edx,edx                ; clear EDX
  752.   xor    edi,edi                ; clear EDI
  753.  
  754.   les    di,[outAddr]            ; load output address
  755.   mov    ax,[y]
  756.   mov    dx,[outScreenWide]
  757.   mul    edx                    ; EDX:EAX = offset - EDI - x
  758.   add    edi,eax                ; EDI = offset - x
  759.   mov    dx,[xOff]
  760.   add    edi,edx                ; EDI = offset
  761.   mov    edx,edi                ; EDX = offset
  762.   shr    edx,4                ; EDX = # of paragraphs (segments)
  763.   add    dx,[outSeg]            ; DX = new segment
  764.   mov    es,dx                ; ES = new segment
  765.   and    di,0000000000001111b             ; DI = offset within new segment
  766.  
  767.   lds    si,[buf]            ; load input address
  768.   mov    dx,si                ; DX = offset
  769.   shr    dx,4                ; DX = # of paragraphs (segments)
  770.   mov    ax,ds                ; AX = DS
  771.   add    ax,dx                ; AX = new DS
  772.   mov    ds,ax                ; DS = new DS
  773.   and    si,0000000000001111b        ; SI = offset within new segment
  774.  
  775.   cld
  776.   mov    cx,[lineLen]            ; CX = line length
  777.   mov    dx,cx                ; DX = line length
  778.   shr    cx,2                ; CX = line length in dwords
  779.   rep    movsd                     ; move the dwords if necessary
  780.   mov    cx,dx                ; CX = line length in bytes
  781.   and    cx,0000000000000011b        ; CX = any residual bytes
  782.   rep    movsb                ; move the bytes if necessary
  783.  
  784.   pop    di si ds            ; restore registers
  785.   leave                    ; clean up
  786.   retf                    ; return
  787. ENDP
  788.  
  789.  
  790. ;*****
  791. ;***** getLine
  792. ;*****
  793.  
  794. PROC    C    getLine_scr
  795.     ARG    lineNum:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  796.     LOCAL    x2:WORD
  797.   push    ds si di
  798.  
  799.   mov    bx,[lineNum]            ; start address in ES:DI
  800.   shl    bx,1
  801.   mov    si,[lineOffs+bx]
  802.   mov    dx,[xOff]
  803.   shr    dx,2
  804.   add    si,dx
  805.   mov    ax,0A000h
  806.   mov    ds,ax
  807.   les    di,[buf]            ; buffer addr in DS:SI
  808.   cld
  809.  
  810.   mov    bx,[xOff]
  811.   add    bx,[lineLen]            ; calculate x2
  812.   dec    bx
  813.   mov    [x2],bx
  814.  
  815.   mov    cx,[lineLen]            ; line is short
  816.   cmp    cx,4
  817. JUMPS
  818.   jle    @@ShortLine
  819. NOJUMPS
  820.  
  821.   mov    ax,[xOff]            ; calculate starting plane
  822.   mov    bx,ax
  823.   and    al,3
  824.   mov    ah,al
  825.   mov    al,READ_MAP
  826.   mov    dx,GC_INDEX
  827.   OUT_WORD
  828.   push    di
  829.   mov    bx,[x2]
  830.   mov    cx,[xOff]
  831.     @@Loop1:
  832.   cmp    cx,bx
  833.   jg    @@Loop1Done
  834.   lodsb
  835.   stosb
  836.   add    cx,4
  837.   add    di,3
  838.   jmp    short    @@Loop1
  839.  
  840.     @@Loop1Done:
  841.   pop    di
  842.   inc    di
  843.   push    di
  844.   mov    bx,[xOff]
  845.   inc    bx
  846.   mov    ax,bx
  847.   and    al,3
  848.   mov    ah,al
  849.   mov    al,READ_MAP
  850.   mov    dx,GC_INDEX
  851.   OUT_WORD
  852.   mov    cx,bx
  853.   mov    bx,[lineNum]            ; start address in ES:DI
  854.   shl    bx,1
  855.   mov    si,[lineOffs+bx]
  856.   shr    cx,2
  857.   add    si,cx
  858.   mov    bx,[x2]
  859.   mov    cx,[xOff]
  860.   inc    cx
  861.     @@Loop2:
  862.   cmp    cx,bx
  863.   jg    @@Loop2Done
  864.   lodsb
  865.   stosb
  866.   add    cx,4
  867.   add    di,3
  868.   jmp    short    @@Loop2
  869.  
  870.     @@Loop2Done:
  871.   pop    di
  872.   inc    di
  873.   push    di
  874.   mov    bx,[xOff]
  875.   add    bx,2
  876.   mov    ax,bx
  877.   and    al,3
  878.   mov    ah,al
  879.   mov    al,READ_MAP
  880.   mov    dx,GC_INDEX
  881.   OUT_WORD
  882.   mov    cx,bx
  883.   mov    bx,[lineNum]
  884.   shl    bx,1
  885.   mov    si,[lineOffs+bx]
  886.   shr    cx,2
  887.   add    si,cx
  888.   mov    bx,[x2]
  889.   mov    cx,[xOff]
  890.   add    cx,2
  891.     @@Loop3:
  892.   cmp    cx,bx
  893.   jg    @@Loop3Done
  894.   lodsb
  895.   stosb
  896.   add    cx,4
  897.   add    di,3
  898.   jmp    short    @@Loop3
  899.  
  900.     @@Loop3Done:
  901.   pop    di
  902.   inc    di
  903.   mov    bx,[xOff]
  904.   add    bx,3
  905.   mov    ax,bx
  906.   and    al,3
  907.   mov    ah,al
  908.   mov    al,READ_MAP
  909.   mov    dx,GC_INDEX
  910.   OUT_WORD
  911.   mov    cx,bx
  912.   mov    bx,[lineNum]
  913.   shl    bx,1
  914.   mov    si,[lineOffs+bx]
  915.   shr    cx,2
  916.   add    si,cx
  917.   mov    bx,[x2]
  918.   mov    cx,[xOff]
  919.   add    cx,3
  920.     @@Loop4:
  921.   cmp    cx,bx
  922.   jg    @@Exit
  923.   lodsb
  924.   stosb
  925.   add    cx,4
  926.   add    di,3
  927.   jmp    short    @@Loop4
  928.  
  929.     @@ShortLine:
  930.   mov    ax,[xOff]
  931.   mov    bx,ax
  932.   and    al,3
  933.   mov    ah,al
  934.   mov    al,READ_MAP
  935.   mov    dx,GC_INDEX
  936.   OUT_WORD
  937.   mov    cx,bx
  938.   shr    bx,2
  939.   mov    si,bx
  940.   mov    bx,[lineNum]
  941.   shl    bx,1
  942.   add    si,[lineOffs+bx]
  943.   movsb
  944.   cmp    cx,[x2]
  945.   jge    @@Exit
  946.   inc    [xOff]
  947.   jmp    short    @@ShortLine
  948.  
  949.     @@Exit:
  950.   pop   di si ds
  951.   leave
  952.   retf
  953. ENDP
  954.  
  955. PROC    C    getLine_mem
  956.     ARG    y:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  957.   push    ds si di            ; save these registers
  958.  
  959.   xor    eax,eax                ; clear EAX
  960.   xor    edx,edx                ; clear EDX
  961.   xor    esi,esi                ; clear ESI
  962.  
  963.   les    si,[inAddr]            ; load input address
  964.   mov    ax,[y]
  965.   mov    dx,[inScreenWide]
  966.   mul    edx                    ; EDX:EAX = offset - ESI - x
  967.   add    esi,eax                ; ESI = offset - x
  968.   mov    dx,[xOff]
  969.   add    esi,edx                ; ESI = offset
  970.   mov    edx,esi                ; EDX = offset
  971.   shr    edx,4                ; EDX = # of paragraphs (segments)
  972.   add    dx,[inSeg]            ; DX = new segment
  973.   mov    ds,dx                ; ES = new segment
  974.   and    si,0000000000001111b             ; SI = offset within new segment
  975.  
  976.   les    di,[buf]            ; load output address
  977.   mov    dx,di                ; DX = offset
  978.   shr    dx,4                ; DX = # of paragraphs (segments)
  979.   mov    ax,es                ; AX = ES
  980.   add    ax,dx                ; AX = new ES
  981.   mov    es,ax                ; ES = new ES
  982.   and    di,0000000000001111b        ; DI = offset within new segment
  983.  
  984.   cld
  985.   mov    cx,[lineLen]            ; CX = line length
  986.   mov    dx,cx                ; DX = line length
  987.   shr    cx,2                ; CX = line length in dwords
  988.   rep    movsd                     ; move the dwords if necessary
  989.   mov    cx,dx                ; CX = line length in bytes
  990.   and    cx,0000000000000011b        ; CX = any residual bytes
  991.   rep    movsb                ; move the bytes if necessary
  992.  
  993.   pop    di si ds            ; restore registers
  994.   leave                    ; clean up
  995.   retf                    ; return
  996. ENDP
  997.  
  998.  
  999. ;*****
  1000. ;***** putPixel
  1001. ;*****
  1002.  
  1003. ; Copy a pixel to the screen
  1004. PROC    C    putPixel_scr_copy
  1005.     ARG    x:WORD, y:WORD, colour:BYTE
  1006.   push    di
  1007.  
  1008.   mov    ax,0A000h
  1009.   mov    es,ax
  1010.   mov    bx,[y]                ; point to start of desired row
  1011.   shl    bx,1
  1012.   mov    bx,[lineOffs+bx]
  1013.   mov    dx,[x]
  1014.   mov    cx,dx                ; store x coord
  1015.   shr    dx,2
  1016.   add    bx,dx
  1017.   mov    di,bx                ; ES:DI points to pixel
  1018.   and    cl,3                ; get the plane # of the pixel
  1019.   mov    ax,102h
  1020.   shl    ah,cl                ; set the bit corresponding to plane
  1021.   mov    dx,SC_INDEX
  1022.   OUT_WORD
  1023.   mov    bl,[colour]
  1024.   mov    [es:di],bl
  1025.  
  1026.   pop    di
  1027.   leave
  1028.   retf
  1029. ENDP
  1030.  
  1031. ; Copy a pixel to memory
  1032. PROC    C    putPixel_mem_copy
  1033.     ARG    x:WORD,y:WORD,colour:BYTE
  1034.   xor    eax,eax                ; clear EAX
  1035.   xor    ebx,ebx                ; clear EBX
  1036.   xor    edx,edx                ; clear EDX
  1037.  
  1038.   les    bx,[outAddr]            ; load output address
  1039.   mov    ax,[y]
  1040.   mov    dx,[outScreenWide]
  1041.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1042.   add    ebx,eax                ; EBX = offset - x
  1043.   mov    dx,[x]
  1044.   add    ebx,edx                ; EBX = offset
  1045.  
  1046.   mov    edx,ebx                ; EDX = offset
  1047.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1048.   add    dx,[outSeg]            ; DX = new segment
  1049.   mov    es,dx                ; ES = new segment
  1050.   and    bx,0000000000001111b             ; BX = offset within new segment
  1051.  
  1052.   mov    al,[colour]            ; colour in AL
  1053.   mov    [es:bx],al            ; store pixel
  1054.   leave                    ; clean up
  1055.   retf                    ; return
  1056. ENDP
  1057.  
  1058. ; AND a pixel to memory
  1059. PROC    C    putPixel_mem_and
  1060.     ARG    x:WORD,y:WORD,colour:BYTE
  1061.   xor    eax,eax                ; clear EAX
  1062.   xor    ebx,ebx                ; clear EBX
  1063.   xor    edx,edx                ; clear EDX
  1064.  
  1065.   les    bx,[outAddr]            ; load output address
  1066.   mov    ax,[y]
  1067.   mov    dx,[outScreenWide]
  1068.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1069.   add    ebx,eax                ; EBX = offset - x
  1070.   mov    dx,[x]
  1071.   add    ebx,edx                ; EBX = offset
  1072.  
  1073.   mov    edx,ebx                ; EDX = offset
  1074.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1075.   add    dx,[outSeg]            ; DX = new segment
  1076.   mov    es,dx                ; ES = new segment
  1077.   and    bx,0000000000001111b             ; BX = offset within new segment
  1078.  
  1079.   mov    al,[colour]            ; colour in AL
  1080.   and    [es:bx],al            ; AND pixel
  1081.   leave                    ; clean up
  1082.   retf                    ; return
  1083. ENDP
  1084.  
  1085. ; NOT a pixel to memory
  1086. PROC    C    putPixel_mem_not
  1087.     ARG    x:WORD,y:WORD,colour:BYTE
  1088.   xor    eax,eax                ; clear EAX
  1089.   xor    ebx,ebx                ; clear EBX
  1090.   xor    edx,edx                ; clear EDX
  1091.  
  1092.   les    bx,[outAddr]            ; load output address
  1093.   mov    ax,[y]
  1094.   mov    dx,[outScreenWide]
  1095.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1096.   add    ebx,eax                ; EBX = offset - x
  1097.   mov    dx,[x]
  1098.   add    ebx,edx                ; EBX = offset
  1099.  
  1100.   mov    edx,ebx                ; EDX = offset
  1101.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1102.   add    dx,[outSeg]            ; DX = new segment
  1103.   mov    es,dx                ; ES = new segment
  1104.   and    bx,0000000000001111b             ; BX = offset within new segment
  1105.  
  1106.   mov    al,[colour]            ; colour in AL
  1107.   not    al                ; NOT it
  1108.   mov    [es:bx],al            ; store NOTed pixel
  1109.   leave                    ; clean up
  1110.   retf                    ; return
  1111. ENDP
  1112.  
  1113. ; OR a pixel to memory
  1114. PROC    C    putPixel_mem_or
  1115.     ARG    x:WORD,y:WORD,colour:BYTE
  1116.   xor    eax,eax                ; clear EAX
  1117.   xor    ebx,ebx                ; clear EBX
  1118.   xor    edx,edx                ; clear EDX
  1119.  
  1120.   les    bx,[outAddr]            ; load output address
  1121.   mov    ax,[y]
  1122.   mov    dx,[outScreenWide]
  1123.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1124.   add    ebx,eax                ; EBX = offset - x
  1125.   mov    dx,[x]
  1126.   add    ebx,edx                ; EBX = offset
  1127.  
  1128.   mov    edx,ebx                ; EDX = offset
  1129.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1130.   add    dx,[outSeg]            ; DX = new segment
  1131.   mov    es,dx                ; ES = new segment
  1132.   and    bx,0000000000001111b             ; BX = offset within new segment
  1133.  
  1134.   mov    al,[colour]            ; colour in AL
  1135.   or    [es:bx],al            ; OR pixel
  1136.   leave                    ; clean up
  1137.   retf                    ; return
  1138. ENDP
  1139.  
  1140. ; XOR a pixel to memory
  1141. PROC    C    putPixel_mem_xor
  1142.     ARG    x:WORD,y:WORD,colour:BYTE
  1143.   xor    eax,eax                ; clear EAX
  1144.   xor    ebx,ebx                ; clear EBX
  1145.   xor    edx,edx                ; clear EDX
  1146.  
  1147.   les    bx,[outAddr]            ; load output address
  1148.   mov    ax,[y]
  1149.   mov    dx,[outScreenWide]
  1150.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1151.   add    ebx,eax                ; EBX = offset - x
  1152.   mov    dx,[x]
  1153.   add    ebx,edx                ; EBX = offset
  1154.  
  1155.   mov    edx,ebx                ; EDX = offset
  1156.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1157.   add    dx,[outSeg]            ; DX = new segment
  1158.   mov    es,dx                ; ES = new segment
  1159.   and    bx,0000000000001111b             ; BX = offset within new segment
  1160.  
  1161.   mov    al,[colour]            ; colour in AL
  1162.   xor    [es:bx],al            ; XOR pixel
  1163.   leave                    ; clean up
  1164.   retf                    ; return
  1165. ENDP
  1166.  
  1167.  
  1168. ;*****
  1169. ;***** getPixel
  1170. ;*****
  1171.  
  1172. ; Get a pixel from the screen
  1173. PROC    C    getPixel_scr
  1174.     ARG    x:WORD, y:WORD
  1175.   push    di
  1176.  
  1177.   mov    ax,0A000h
  1178.   mov    es,ax
  1179.   mov    bx,[y]                ; point to start of desired row
  1180.   shl    bx,1
  1181.   mov    bx,[lineOffs+bx]
  1182.   mov    dx,[x]
  1183.   mov    cx,dx                ; store x coord
  1184.   shr    dx,2
  1185.   add    bx,dx
  1186.   mov    di,bx                ; ES:DI points to pixel
  1187.   and    cl,3                ; get the plane # of the pixel
  1188.   mov    al,READ_MAP
  1189.   mov    ah,cl
  1190.   mov    dx,GC_INDEX            ; set the bit corresponding to plane
  1191.   OUT_WORD
  1192.   xor    ax,ax
  1193.   mov    al,[es:di]
  1194.  
  1195.   pop    di
  1196.   leave
  1197.   retf
  1198. ENDP
  1199.  
  1200. ; Get a pixel from memory
  1201. PROC    C    getPixel_mem
  1202.     ARG    x:WORD,y:WORD
  1203.   xor    eax,eax                ; clear EAX
  1204.   xor    ebx,ebx                ; clear EBX
  1205.   xor    edx,edx                ; clear EDX
  1206.  
  1207.   les    bx,[inAddr]            ; load input address
  1208.   mov    ax,[y]
  1209.   mov    dx,[inScreenWide]
  1210.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1211.   add    ebx,eax                ; EBX = offset - x
  1212.   mov    dx,[x]
  1213.   add    ebx,edx                ; EBX = offset
  1214.  
  1215.   mov    edx,ebx                ; EDX = offset
  1216.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1217.   add    dx,[inSeg]            ; DX = new segment
  1218.   mov    es,dx                ; ES = new segment
  1219.   and    bx,0000000000001111b             ; BX = offset within new segment
  1220.  
  1221.   xor    ax,ax                ; clear AX
  1222.   mov    al,[es:bx]            ; store pixel in AX for return
  1223.   leave                    ; clean up
  1224.   retf                    ; return
  1225. ENDP
  1226.  
  1227.  
  1228. ;*****
  1229. ;***** horizLine
  1230. ;*****
  1231.  
  1232. PROC    C    horizLine_scr_copy
  1233.     ARG    y:WORD, x1:WORD, x2:WORD, colour:BYTE
  1234.     LOCAL    adj1:WORD, adj2:WORD
  1235.   push    si di
  1236.   cld
  1237.  
  1238.   mov    ax,[x1]                ; set up adj1
  1239.   and    ax,3
  1240.   jz    @@adj1A
  1241.   mov    bx,4
  1242.   sub    bx,ax
  1243.   mov    ax,[x1]
  1244.   add    ax,bx
  1245.   mov    [adj1],ax
  1246.   jmp    short    @@adj1B
  1247.     @@adj1A:
  1248.   mov    ax,[x1]
  1249.   mov    [adj1],ax
  1250.     @@adj1B:
  1251.  
  1252.   mov    ax,[x2]                ; set up adj2
  1253.   mov    [adj2],ax
  1254.   and    ax,3
  1255.   sub    [adj2],ax
  1256.  
  1257.   mov    ax,[x1]                ; ensure x1 <= x2
  1258.   cmp    ax,[x2]
  1259.   jbe    @@setup
  1260.   mov    bx,[x2]
  1261.   mov    [x1],bx
  1262.   mov    [x2],ax
  1263.  
  1264.     @@setup:
  1265.   mov    ax,0A000h            ; set ES:DI to line start address
  1266.   mov    es,ax
  1267.   mov    bx,[y]
  1268.   shl    bx,1
  1269.   mov    di,[lineOffs+bx]
  1270.   mov    bx,[x1]                ; current x counter
  1271.   shr    bx,2
  1272.   add    di,bx
  1273.  
  1274.   mov    cx,[adj2]            ; CX = # of 4-pixel sets starting
  1275.   shr    cx,2                            ; on plane 0
  1276.   mov    bx,[adj1]
  1277.   shr    bx,2
  1278.   sub    cx,bx
  1279.  
  1280.   cmp    cx,1
  1281.   jl    @@shortLine
  1282.  
  1283.   ; Draw the left edge
  1284.   mov    ax,[x1]                ; get plane number of pixel #1
  1285.   and    ax,3
  1286.   jz    @@planeZeroStart        ; starts at plane zero
  1287.   mov    si,ax                ; set for pixels
  1288.   mov    ah,[leftEdgeMask+si]
  1289.   mov    al,MAP_MASK
  1290.   mov    dx,SC_INDEX
  1291.   OUT_WORD
  1292.   mov    al,[colour]
  1293.   stosb
  1294.  
  1295.   ; Draw the interior stretch
  1296.     @@planeZeroStart:
  1297.   mov    ax,0F02h            ; enable writes to all planes
  1298.   mov    dx,SC_INDEX
  1299.   OUT_WORD
  1300.   mov    al,[colour]
  1301.   mov    ah,al
  1302.   shr    cx,1
  1303.   jc    @@Odd
  1304.   rep    stosw                ; even number of pixels
  1305.   jmp    short    @@rightEdge
  1306.     @@Odd:
  1307.   rep    stosw                ; odd number of pixels
  1308.   stosb
  1309.  
  1310.   ; Draw the right edge
  1311.     @@rightEdge:
  1312.   mov    ax,[x2]                ; get plane number of last pixel
  1313.   and    ax,3
  1314.   mov    si,ax                ; set for pixels
  1315.   mov    ah,[rightEdgeMask+si]
  1316.   mov    al,MAP_MASK
  1317.   mov    dx,SC_INDEX
  1318.   OUT_WORD
  1319.   mov    al,[colour]
  1320.   stosb
  1321.  
  1322.     @@Exit:
  1323.   pop    di si                ; clean up and go home
  1324.   leave
  1325.   retf
  1326.  
  1327.     @@shortLine:            ; for very small lines
  1328.   mov    al,[colour]
  1329.   mov    cx,[x1]
  1330.   mov    dx,[y]
  1331.     @@Loop:
  1332.   push    ax cx dx            ; slow loop until done
  1333.   call    putPixel_scr_copy C, cx, dx, ax
  1334.   pop    dx cx ax
  1335.   inc    cx
  1336.   cmp    cx,[x2]
  1337.   jle    @@Loop
  1338.  
  1339.   pop     di si
  1340.   leave
  1341.   retf
  1342. ENDP
  1343.  
  1344. PROC    C    horizLine_mem_copy
  1345.     ARG    y:WORD, x1:WORD, x2:WORD, colour:BYTE
  1346.   push    edi                ; store EDI
  1347.  
  1348.   xor    eax,eax                ; clear EAX
  1349.   xor    edi,edi                ; clear EDI
  1350.   xor    edx,edx                ; clear EDX
  1351.  
  1352.   les    di,[outAddr]            ; load output address
  1353.   mov    ax,[y]
  1354.   mov    dx,[outScreenWide]
  1355.   mul    edx                    ; EDX:EAX = offset - EDI - x
  1356.   add    edi,eax                ; EDI = offset - x
  1357.   mov    dx,[x1]
  1358.   add    edi,edx                ; EDI = offset
  1359.   mov    edx,edi                ; EDX = offset
  1360.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1361.   add    dx,[outSeg]            ; DX = new segment
  1362.   mov    es,dx                ; ES = new segment
  1363.   and    di,0000000000001111b             ; DI = offset within new segment
  1364.  
  1365.   mov    al,[colour]            ; colour in AL
  1366.   mov    ah,al                ; colour in AH
  1367.   mov    bx,ax
  1368.   shl    eax,16
  1369.   mov    ax,bx                 ; colour in each byte of EAX
  1370.  
  1371.   mov    cx,[x2]
  1372.   sub    cx,[x1]
  1373.   inc    cx                ; CX = line length in pixels
  1374.   mov    dx,cx                ; DX = line length in bytes
  1375.  
  1376.   shr    cx,2                ; CX = line length in dwords
  1377.   rep    stosd                ; store four bytes at a time
  1378.   mov    cx,dx                ; CX = line length in pixels
  1379.   and    cx,0000000000000011b        ; CX = any remaining bytes
  1380.   rep    stosb                ; store the remaining bytes
  1381.  
  1382.   pop    edi                    ; restore EDI
  1383.   leave                    ; clean up
  1384.   retf                    ; return
  1385. ENDP
  1386.  
  1387.  
  1388. ;*****
  1389. ;***** setPaletteReg
  1390. ;*****
  1391.  
  1392. PROC    C    setPaletteReg
  1393.     ARG    palNum:WORD,red:BYTE,green:BYTE,blue:BYTE
  1394.   mov    bx,[palNum]
  1395.  
  1396.   mov    dx,3C8h                ; set for the right palette register
  1397.   mov    ax,[palNum]
  1398.   out    dx,al
  1399.   inc    dx
  1400.  
  1401.   mov    al,[red]            ; red
  1402.   shr    al,2
  1403.   jnc    @@L1
  1404.   cmp    al,63
  1405.   je    @@L1
  1406.   inc    al
  1407.     @@L1:
  1408.   out    dx,al
  1409.  
  1410.   mov    al,[green]            ; green
  1411.   shr    al,2
  1412.   jnc    @@L2
  1413.   cmp    al,63
  1414.   je    @@L2
  1415.   inc    al
  1416.     @@L2:
  1417.   out    dx,al
  1418.  
  1419.   mov    al,[blue]            ; blue
  1420.   shr    al,2
  1421.   jnc    @@L3
  1422.   cmp    al,63
  1423.   je    @@L3
  1424.   inc    al
  1425.     @@L3:
  1426.   out    dx,al
  1427.  
  1428.   leave
  1429.   retf
  1430. ENDP
  1431.  
  1432.  
  1433. ;*****
  1434. ;***** getPaletteReg
  1435. ;*****
  1436.  
  1437. PROC    C    getPaletteReg
  1438.     ARG    palNum:WORD,red:DATAPTR,green:DATAPTR,blue:DATAPTR
  1439.   push    ds si
  1440.  
  1441.   mov    dx,3C7h                ; set for right palette register
  1442.   mov    ax,[palNum]
  1443.   out    dx,al
  1444.   mov    dx,3C9h
  1445.  
  1446.   in    al,dx                ; red
  1447.   lds    si,[red]
  1448.   shl    al,2
  1449.   mov    [ds:si],al
  1450.   in    al,dx                ; green
  1451.   lds    si,[green]
  1452.   shl    al,2
  1453.   mov    [ds:si],al
  1454.   in    al,dx                ; blue
  1455.   lds    si,[blue]
  1456.   shl    al,2
  1457.   mov    [ds:si],al
  1458.  
  1459.   pop    si ds
  1460.   leave
  1461.   retf
  1462. ENDP
  1463.  
  1464.  
  1465. ;*****
  1466. ;***** setBlockPalette
  1467. ;*****
  1468.  
  1469. PROC    C    setBlockPalette
  1470.     ARG    firstReg:WORD,lastReg:WORD,paletteData:DATAPTR
  1471.   push    ds si
  1472.  
  1473.   lds    si,[paletteData]        ; set up
  1474.   mov    dx,3C8h
  1475.   mov    ax,[firstReg]
  1476.   out    dx,al
  1477.   inc    dx
  1478.   mov    cx,[lastReg]            ; CX = number of registers
  1479.   sub    cx,ax
  1480.   inc    cx
  1481.   cld
  1482.  
  1483.     @@LLoop:
  1484.   lodsb            ; red
  1485.   shr    al,2
  1486.   jnc    @@L1
  1487.   cmp    al,63
  1488.   je    @@L1
  1489.   inc    al
  1490.       @@L1:
  1491.   out    dx,al
  1492.  
  1493.   lodsb            ; green
  1494.   shr    al,2
  1495.   jnc    @@L2
  1496.   cmp    al,63
  1497.   je    @@L2
  1498.   inc    al
  1499.       @@L2:
  1500.   out    dx,al
  1501.  
  1502.   lodsb            ; blue
  1503.   shr    al,2
  1504.   jnc    @@L3
  1505.   cmp    al,63
  1506.   je    @@L3
  1507.   inc    al
  1508.       @@L3:
  1509.   out    dx,al
  1510.  
  1511.   loop    @@LLoop
  1512.  
  1513.     @@LExit:
  1514.   pop    si ds
  1515.   leave
  1516.   retf
  1517. ENDP
  1518.  
  1519.  
  1520. ;*****
  1521. ;***** getBlockPalette
  1522. ;*****
  1523.  
  1524. PROC    C    getBlockPalette
  1525.     ARG    firstReg:WORD,lastReg:WORD,paletteData:DATAPTR
  1526.   push    di
  1527.  
  1528.   les    di,[paletteData]        ; set up
  1529.   mov    dx,3C7h
  1530.   mov    ax,[firstReg]
  1531.   out    dx,al
  1532.   mov    dx,3C9h
  1533.   mov    cx,[lastReg]            ; CX = number of registers
  1534.   sub    cx,ax
  1535.   inc    cx
  1536.   cld
  1537.  
  1538.     @@L1:
  1539.   in    al,dx
  1540.   shl    al,2
  1541.   stosb            ; red
  1542.   in    al,dx
  1543.   shl    al,2
  1544.   stosb            ; green
  1545.   in    al,dx
  1546.   shl    al,2
  1547.   stosb            ; blue
  1548.   loop    @@L1
  1549.  
  1550.     @@LExit:
  1551.   pop    di
  1552.   leave
  1553.   retf
  1554. ENDP
  1555.  
  1556.  
  1557. ;*****
  1558. ;***** clearGraphics
  1559. ;*****
  1560.  
  1561. PROC    C    clearGraphics_scr_copy
  1562.     ARG    colour:BYTE
  1563.   mov   dx,SC_INDEX
  1564.   mov   ax,0F02h
  1565.   out   dx,ax               ; enable writes to all four planes
  1566.  
  1567.   mov    ax,0A000h
  1568.   mov    es,ax
  1569.   xor    di,di
  1570.   cld
  1571.   mov    cx,9600
  1572.   mov    al,[colour]
  1573.   mov    ah,al
  1574.  
  1575.   rep    stosw
  1576.   leave
  1577.   retf
  1578. ENDP
  1579.  
  1580.  
  1581.     ENDS
  1582. END